<?php
define('Acache_no','1');
class Con_admin extends Acan{
	
	public $defaultAct='abody';
	public $Conread = '后台';
	public $Actread = array('abody'=>'框架','index'=>'首页','count'=>'统计');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		$this->atitle = $this->Actread[$this->Aact];
	}
	//后台框架
	function Act_abody(){
		$anav_data = Afunc_nav()->anav_data('danhao',$this->Amode,$this->Aapp);//获取菜单
		if($this->Amode == '0'){$if_start = $this->Aapp.'-';}else{$if_start='';}
		$default_url = $if_start.'admin-index';
		include $this->Atpl('public/abody');
	}
	//后台首页
	function Act_index(){
		$today = date('Y-m-d');
		$con->select='SUM(cash) as cash';
		$con->where="`update`>'$today' and type=21 and status=2";
		$chongzhi = Afun_db()->model(Acan_table_danhao_cash)->find($con);
		$con->where="`update`>'$today' and type=2";
		$goumai = Afun_db()->model(Acan_table_danhao_cash)->find($con);
		$cash_total = $chongzhi['cash']*2+$goumai['cash'];
		$con->select='count(uid) as uids';
		$con->where="regdate>'$today'";
		$user = Afun_db()->model(Acan_table_user)->find($con);
		$con->select='count(id) as total';
		$con->where="`update`>'$today'";
		$danhao = Afun_db()->model(Acan_table_danhao_express)->find($con);
		include $this->Atpl();
	}
	//统计
	function Act_count(){
		$con->select='SUM(money) as money,SUM(cash) as cash,SUM(free) as free';
		$info_sum = Afun_obj_arr(Afun_db()->model(Acan_table_user_info)->ofind($con));
		$info_total = $info_sum[cash]+$info_sum[free];
		unset($con);
		$con->select='SUM(cash) as cash';
		$con->where='type=21 and status=2';
		$chongzhi = Afun_db()->model(Acan_table_danhao_cash)->find($con);
		$con->where='type=2';
		$goumai = Afun_db()->model(Acan_table_danhao_cash)->find($con);
		$cash_tatol = $chongzhi['cash']*2+$goumai['cash'];
		include $this->Atpl();
	}
	function Act_stat(){
		$this->atitle = '快号 充值/消费表';
		$rs = Afun_cache_get('stat:totalpay');
		if(!$rs){
			$model = Afun_db()->model(Acan_table_danhao_cash);
			$startdata = date('Y-m-d',time()-86400*6).' 00:00:00';
			$con->select = "left(a.`update`,10) as date,count(a.cash) as nums,SUM(a.cash) as money";
			$con->where = "type=21 and status=2 and `update`>'$startdata'";
			$con->group = 'date';
			$con->order = 'date ASC';
			$rs = $model->findAll($con);
			Afun_cache_set('stat:totalpay',$rs,600);
		}
		if(is_array($rs))
		foreach ($rs as $k => $v) {
			$drr[] = $v['date'];
			$mrr[] = $v['money'];
			$nrr[] = $v['nums'];
		}
		$json_date = json_encode($drr);
		$json_num = json_encode($nrr);
		$json_money = json_encode($mrr);
		if($nrr) $total_num = array_sum($nrr); else $total_num = 0;
		if($mrr) $total_money = array_sum($mrr); else $total_money = 0;
		if(($total_num+$total_money)>0) $avg = round($total_money/$total_num,1);else $avg = 0;
		$dayavg = round($total_money/7,1);
		/*
		//--统计7日内各菜品销量
		$rs = Afun_cache_get('stat:7dayin');
		if(!$rs){
			$where = " WHERE i.optime>?";
			$group = ' GROUP BY i.name,i.kindmenuid ORDER BY i.kindmenuid ASC,num DESC';
			$rs = $this->pgsql->findAll("SELECT i.name,count(i.name) as num FROM instance i".$where.$group,(time()-86400*8)*1000);
			Afun_cache_set('stat:7dayin',$rs,3600);
		}
		$day5max = 0;
		foreach ($rs['data'] as $k => $v) {
			if($day5max<$v['num']) $day5max=$v['num'];
			$arr['name'] = $v['name'];
			$arr['value'] = $v['num'];
			$arr['color']='#FF3333';
			$day5data[] = $arr;
		}
		$json_day5data = json_encode($day5data);
		*/
		include $this->Atpl();
	}
}

?>